
<script>
function initSprintModal(){
	$("#dialog-sprint").dialog({
		autoOpen: false,
		height: 240,
		width: 500,
		position: 'top',
		modal: true,
		buttons: {
			"Save": function(){
				var validation=$("#form_upsert_sprint").validationEngine('validate');
				if(validation){
					document.forms["form_upsert_sprint"].submit();
					$(this).dialog("close");
				};
			},
			Cancel: function() {
			$( this ).dialog( "close" );
		}
		},
		close: function() {
			$("#form_upsert_sprint").validationEngine('hideAll');
		}
	});
}
$(document).ready(function() {
    //$("#list2").validationEngine();    
});
</script>
		
<script type="text/javascript">
	$(document).ready(function(){
		$("#list2").jqGrid({
		   	url:'<?= base_url() ?>index.php/sprint/getSprints/',
			datatype: "json",
			mtype : "post",
		   	colNames:['Id','Start Date', 'End Date', 'Status', 'Action'],
		   	colModel:[
		   		{name:'Id',index:'Id', width:150},
		   		{name:'Start Date',index:'Start Date', width:250},
		   		{name:'End Date',index:'End Date', width:250},
		   		{name:'Status',index:'Status', width:220},
		   		{name:'action', index:'action', width:40, formatter:sprintsFormatOperations}
		   	],
		   	rowNum:10,
		   	height:400,
		   	rowList:[10,20,30],
		   	pager: '#pager2',
		   	sortname: 'id',
		    sortorder: "asc",
		    viewrecords: true,
		    caption:"Sprints List"
		});	
		
	jQuery("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false, search:false, del:false});
		$("#list2").navButtonAdd('#pager2', {  
			 caption: "New Sprint",   
		 	title: "Click here to create a sprint",   
		 	buttonicon: "ui-icon-plusthick",   
		 	onClickButton: function() { 
				openSprintDialog();
		  		},  position: "first" 
			  		});

		initSprintModal();
	});
	function openSprintDialog(){
		emptySprintFields();
		$( "#dialog-sprint" ).dialog( "open" );
	}
	function emptySprintFields()
	{
		$("#dateIni").val("");
		$("#dateEnd").val("");
		$("#status").val("Open");
	}
	function sprintsFormatOperations(cellvalue, options, rowObject) {
		return 	"<a href='#' onclick=editSprint(" + rowObject[0] + ")><img src=" + CI.baseUrl + "/img/edit2.png></img></a>" +
				"<a href='#' onclick=deleteSprint(" + rowObject[0] + ")><img src=" + CI.baseUrl + "/img/delete.png></img></a>";
	}
	function editSprint(idSprint){
		$.ajax({
			url: CI.baseUrl + '/index.php/sprint/get',
			type: 'POST',
			data: {'id': idSprint},
			dataType: "json",
			success: function(data){
				editSprintDialog(data);
			},
			error: function(data){
				alert('error');
			}
		});
	}
	function editSprintDialog(sprintData){
		$("#dateIni").val(sprintData.start_date);
		$("#dateEnd").val(sprintData.end_date);
		$("#status_sprint").val(sprintData.status);
		$( "#dialog-sprint" ).dialog( "open" );
	}
</script>
	<div class="ui-widget-content">
		<table id="list2"></table> 
		<div id="pager2"></div>
		<?php $this->load->view('sprint_upsert_view'); ?>
	</div>
	</body>
</html>